//
//  SettingViewController.m
//  KYProject
//
//  Created by Roman on 16/12/20.
//  Copyright © 2016年 Roman. All rights reserved.
//

#import "SettingViewController.h"
#import "FeedbackController.h"
#import "ThePlusSymbolController.h"
#import "MPasswordController.h"
#import "DefineConstant.h"
static NSString *cellId = @"cellId";
@interface SettingViewController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation SettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UITableView *tableView = [[UITableView alloc]initWithFrame:self.view.bounds  style:UITableViewStylePlain];
    [self.view addSubview:tableView];
    tableView.dataSource = self;
    tableView.delegate = self;
    tableView.rowHeight = 45;
    tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    
    //注册
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellId];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    NSArray *arr = @[@"意见反馈",@"加号符号说明",@"修改密码",@"注销用户"];
    cell.textLabel.text = arr[indexPath.row];
    cell.textLabel.font = MYFONT(15);
    //设置分割线
    UIImageView *separatView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"table_item_bk_with_top_gray_corner"]];
    [cell.contentView addSubview:separatView];
    
    [separatView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.equalTo(cell.contentView);
        make.height.mas_equalTo(5);
    }];
    return cell;
}

#pragma mark - 点击cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //意见反馈控制器
    FeedbackController *vc = [[FeedbackController alloc]init];
    
    //加号符号控制器
    
    ThePlusSymbolController *plus = [[ThePlusSymbolController alloc]init];
    
    //修改密码控制器
    MPasswordController *password = [[MPasswordController alloc]init];
    
    if (indexPath.row == 0) {
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if (indexPath.row == 1)
    {
        [self.navigationController pushViewController:plus animated:YES];
    }
    else if (indexPath.row == 2)
    {
        [self.navigationController pushViewController:password animated:YES];
    }
    else if (indexPath.row == 3)
    {
        UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"你确定要注销么" preferredStyle:UIAlertControllerStyleActionSheet];
        //默认只有标题 没有操作的按钮:添加操作的按钮 UIAlertAction
        UIAlertAction *cancelBtn = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action)
        {
            NSLog(@"取消");
        }];
        //添加确定
        
        UIAlertAction *sureBtn = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
            NSLog(@"确定");
            
#pragma mark - 注销
            if(self.cancellationBlock)
            {
                self.cancellationBlock();
            }
            // kIsUserLoginKey = nil;
            
            [self.navigationController popViewControllerAnimated:YES];
        }];
        //将action添加到控制器
        [alertVc addAction:cancelBtn];
        [alertVc addAction:sureBtn];
        //展示
        [self presentViewController:alertVc animated:YES completion:nil];
}
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
